Fix update --precise with the registry source
authorAlex Crichton <alex@alexcrichton.com>
Tue, 19 Jan 2016 20:06:58 +0000 (12:06 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 19 Jan 2016 20:06:58 +0000 (12:06 -0800)
There was a previous bug where if any crate's name was the start of the crate
being updated that the crate wouldn't resolve at all, and this fixes the prefix
checking error bug.

cc #2293

src/cargo/sources/registry.rs
tests/test_cargo_registry.rs

index 7a7822a670b47582c23224610ac845ff49f18fef..438901d8e8169c89a67bb43a1fd77d3b4c7d3618 100644 (file)
@@ -505,7 +505,8 @@ impl<'cfg> Registry for RegistrySource<'cfg> {
         // version requested (agument to `--precise`).
         summaries.retain(|s| {
             match self.source_id.precise() {
-                Some(p) if p.starts_with(dep.name()) => {
+                Some(p) if p.starts_with(dep.name()) &&
+                           p[dep.name().len()..].starts_with("=") => {
                     let vers = &p[dep.name().len() + 1..];
                     s.version().to_string() == vers
                 }
index e9a4528757f0ed148412eb6b825e5643e92c7666..b9c9865198462b5186137512c0425e0c942d3654 100644 (file)
@@ -932,3 +932,27 @@ test!(bundled_crate_in_registry {
 
     assert_that(p.cargo("run"), execs().with_status(0));
 });
+
+test!(update_same_prefix_oh_my_how_was_this_a_bug {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "ugh"
+            version = "0.5.0"
+            authors = []
+
+            [dependencies]
+            foo = "0.1"
+        "#)
+        .file("src/main.rs", "fn main() {}");
+    p.build();
+
+    Package::new("foobar", "0.2.0").publish();
+    Package::new("foo", "0.1.0")
+        .dep("foobar", "0.2.0")
+        .publish();
+
+    assert_that(p.cargo("generate-lockfile"), execs().with_status(0));
+    assert_that(p.cargo("update").arg("-pfoobar").arg("--precise=0.2.0"),
+                execs().with_status(0));
+});